package com.ts.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ts.core.entity.Vo.BloggerVo;
import com.ts.core.entity.LxbBlogger;
import com.ts.core.mapper.LxbBloggerMapper;
import com.ts.core.service.LxbBloggerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2024-03-19
 */
@Service
public class LxbBloggerServiceImpl extends ServiceImpl<LxbBloggerMapper, LxbBlogger> implements LxbBloggerService {

    @Override
    public IPage<LxbBlogger> getlistPage(Page<LxbBlogger> page1, String keyword) {
        if(StringUtils.isBlank(keyword))
        {
            return baseMapper.selectPage(page1,null);
        }
        QueryWrapper<LxbBlogger> wrapper = new QueryWrapper<>();
        wrapper.like("name",keyword).orderByDesc("id");
        Page<LxbBlogger> bloggerPage = baseMapper.selectPage(page1, wrapper);
        return bloggerPage;
    }

    @Override
    public void SetState(String id) {
        LxbBlogger lxbBlogger = baseMapper.selectById(id);
        if (lxbBlogger.getSort()==1) {
            lxbBlogger.setSort(0);
        }
        else
        {
            lxbBlogger.setSort(1);
        }
        baseMapper.updateById(lxbBlogger);

    }

    @Override
    public Boolean insertBloggerToTable(BloggerVo bloggerVo) {
        LxbBlogger lxbBlogger = new LxbBlogger();
        BeanUtils.copyProperties(bloggerVo,lxbBlogger);
        int insert = baseMapper.insert(lxbBlogger);
        if(insert<1){
            return false;
        }

        // id is_deleted  create_time  update_time


        return true;
    }
}
